var setupTask, eim, map;
var reviveCount = 100;
var 最少参与人数 = 1;
var eventName = "活动_跑旗赛7点";
var mapIds = [932200200];
var 准备地图 = 932200003;

function init() {
    em.setProperty("rank", "0");
    em.setProperty("gate", "0");
    em.setProperty("time", "0");
    em.setProperty("state", "0")
}

function setup(c, a) {
    var c = em.newInstance(eventName);
    for (var b = 0; b < mapIds.length; b++) {
        var d = c.setInstanceMap(mapIds[b]);
        em.setProperty("state", "1");
        c.startEventTimer(1000 * 60 * 10);
        setupTask = em.schedule("checkPlayer", 1000 * 1 * 8, c)
    }
    return c
}

function onPlayerRegistered(b, a) {
    var c = b.getMapInstance(0);
    a.changeMap(c, c.getPortal(0))
}

function onMapChanged(c, b, a) {
    if (mapIds.indexOf(a) < 0) {
        on玩家退场(c, b, false);
        return
    }
    switch (a) {
        case 932200200:
            break
    }
}

function onTimeOut(a) {
    a.getPlayers().forEach(function (b) {
        on玩家退场(a, b, true);
        b.getAPI().onActionBarResult(6, 22)
    })
	em.warpAllPlayer(932200200, 932200004);
}

function checkPlayer(b, a) {
    map = b.getMapInstance(932200200);
    if (b.getMapFactoryMap(932200200).getCharactersSize() < 最少参与人数) {
        b.schedule("checkPlayer", 1000 * 5);
        map.startMapEffect("参赛选手不足" + 最少参与人数 + "人,等待其他选手入场.", 5121050)
    } else {
        em.setProperty("time", "2");
        em.setProperty("gate", "2");
        b.startEventTimer(1000 * 60 * 10);
        em.broadcastServerMsg(5121033, "[跑旗赛]：跑旗赛开始进行啦！", true);
        b.getPlayers().forEach(function (c) {
            c.getAPI().onActionBarResult(5, 22);
            c.getAPI().onActionBarResult(11, 22, 2023295, 0, 0);
            c.getAPI().onActionBarResult(11, 22, 2023296, 0, 0);
            c.getAPI().onActionBarResult(11, 22, 2023297, 9, 0);
            c.getAPI().onActionBarResult(11, 22, 2023298, 9, 0)
        })
    }
}

function Chuansong(b, a) {
    warp(b, 准备地图, 0)
}

function openNpc(c, b, d) {
    for (var a = 0; a < c.getPlayerCount(); a++) {
        c.getPlayers().get(a).getAPI().openNpc(b, d)
    }
}

function warp(d, c, a) {
    for (var b = 0; b < d.getPlayerCount(); b++) {
        d.getPlayers().get(b).getAPI().warp(c, a)
    }
}

function randomNum(b, a) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * b + 1, 10);
            break;
        case 2:
            return parseInt(Math.random() * (a - b + 1) + b, 10);
            break;
        default:
            return 0;
            break
    }
}

function initProp(a, b) {
    if (em.getProperty(a) == null) {
        em.setProperty(a, b)
    }
}

function initPropArray(a, d, c, e) {
    for (var b = c; b <= e; b++) {
        if (em.getProperty(a + "_" + b) == null) {
            em.setProperty(a + "_" + b, d)
        }
    }
}

function on玩家退场(c, b, a) {
    em.getProperties().clear();
    em.setProperty("state", 0);
    em.setProperty("leader", "true");
    c.unregisterPlayer(b);
    c.disposeIfPlayerBelow(a ? 999 : 0, 准备地图)
}

function onPlayerRevived(b, a) {}

function onMonsterKilled(a, b) {}

function onPartyDisbanded(a) {}

function onPlayerKilled(b, a) {}

function onMonsterDamaged(b, a, d, e, c) {}

function onPlayerDisconnected(b, a) {
    on玩家退场(b, a, false);
    return 0
};